package com.kltn.zigo.data.adapter;

import java.util.HashMap;

import android.app.Activity;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.kltn.zigo.R;
import com.kltn.zigo.data.IP;
import com.kltn.zigo.data.loader.PlaceDetailLoader;
import com.kltn.zigo.process.ImageLoader;

public class PlaceDetailAdapter extends BaseAdapter{
    
    private Activity activity;
    private HashMap<String, String> data;
    private static LayoutInflater inflater=null;
    private PlaceDetailLoader placedetailloader;
    public ImageLoader imageLoader; 
    
    public PlaceDetailAdapter(Activity a, PlaceDetailLoader pl) {
        activity = a;
        data=pl.GetPlace();
        inflater = (LayoutInflater)activity.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        imageLoader=new ImageLoader(activity.getApplicationContext());
        placedetailloader = pl;        
    }
    
    public PlaceDetailAdapter(Activity a, PlaceDetailLoader pl, HashMap<String, String> d) {
        activity = a;
        data=d;
        inflater = (LayoutInflater)activity.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        imageLoader=new ImageLoader(activity.getApplicationContext());
        placedetailloader = pl;
    }

    public int getCount() {
        return data.size();
    }

    public Object getItem(int position) {
        return position;
    }

    public long getItemId(int position) {
        return position;
    }
    
    public View getView(int position, View convertView, ViewGroup parent) {
        View vi=convertView;
        if(convertView==null)
            vi = inflater.inflate(R.layout.activity_place_detail, null);

        TextView place_id = (TextView)vi.findViewById(R.id.tvID);
        TextView place_name = (TextView)vi.findViewById(R.id.tvPlaceName);
        TextView address = (TextView)vi.findViewById(R.id.tvPlaceAddress); 
        TextView phone = (TextView)vi.findViewById(R.id.tvPhone);     
        TextView fax = (TextView)vi.findViewById(R.id.tvFax);    
        TextView email = (TextView)vi.findViewById(R.id.tvEmail);        
        TextView website = (TextView)vi.findViewById(R.id.tvWebsite);
        TextView opentime = (TextView)vi.findViewById(R.id.tvTimeOpen);
        TextView closetime = (TextView)vi.findViewById(R.id.tvTimeClose);
        TextView lowestprice = (TextView)vi.findViewById(R.id.tvLowestprice);
        TextView hightestprice = (TextView)vi.findViewById(R.id.tvHightestprice);     
        TextView utility = (TextView)vi.findViewById(R.id.tvUtility);     
        TextView spaceplace = (TextView)vi.findViewById(R.id.tvSpacePlace);    
        TextView groupcus = (TextView)vi.findViewById(R.id.tvGroupCustomer);  
        TextView description = (TextView)vi.findViewById(R.id.tvDescription);                                   
        ImageView thumb_image=(ImageView)vi.findViewById(R.id.list_image); 
        
        HashMap<String, String> place = new HashMap<String, String>();
        place = data;
        String Url_avatar = IP.get_IP() + IP.get_path_avatar() + place.get(placedetailloader.TAG_NAME_AVATAR);
        // Setting all values in listview
        place_id.setText(place.get(placedetailloader.TAG_PLACE_ID));
        place_name.setText(place.get(placedetailloader.TAG_PLACE_NAME));
        address.setText(place.get(placedetailloader.TAG_ADDRESS) 
        				+ " - " + place.get(placedetailloader.TAG_DISTRICT_NAME) 
        				+ " - " + place.get(placedetailloader.TAG_PROVINCE_NAME));
        phone.setText(place.get(placedetailloader.TAG_PHONE_NUMBER));
        fax.setText(place.get(placedetailloader.TAG_FAX_NUMBER));
        email.setText(place.get(placedetailloader.TAG_EMAIL));
        website.setText(place.get(placedetailloader.TAG_WEBSITE));
        opentime.setText(place.get(placedetailloader.TAG_OPEN_TIME));
        closetime.setText(place.get(placedetailloader.TAG_CLOSE_TIME));
        lowestprice.setText(place.get(placedetailloader.TAG_LOWEST_PRICE));
        hightestprice.setText(place.get(placedetailloader.TAG_HIGHTEST_PRICE));
        utility.setText(place.get(placedetailloader.TAG_UTILITY));
        spaceplace.setText(place.get(placedetailloader.TAG_SPACE_PLACE));
        groupcus.setText(place.get(placedetailloader.TAG_GROUP_CUSTOMER));
        description.setText(place.get(placedetailloader.TAG_DESCRIPTION));
        imageLoader.DisplayImage(Url_avatar , thumb_image);
        return vi;
    }
}